package com.tjec.project.projectWorkbench.service.impl;

import java.util.List;
import java.util.UUID;

import com.tjec.common.utils.DateUtils;
import com.tjec.common.utils.SecurityUtils;
import com.tjec.common.utils.ServletUtils;
import com.tjec.framework.security.service.TokenService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tjec.project.projectWorkbench.mapper.BmsProjectMemberHistoryMapper;
import com.tjec.project.projectWorkbench.domain.BmsProjectMemberHistory;
import com.tjec.project.projectWorkbench.service.IBmsProjectMemberHistoryService;

/**
 * 项目成员变更历史Service业务层处理
 * 
 * @author cjj
 * @date 2020-04-13
 */
@Service
public class BmsProjectMemberHistoryServiceImpl implements IBmsProjectMemberHistoryService 
{
    @Autowired
    private BmsProjectMemberHistoryMapper bmsProjectMemberHistoryMapper;
    
    @Autowired
    private TokenService tokenService;

    /**
     * 查询项目成员变更历史
     * 
     * @param guid 项目成员变更历史guid
     * @return 项目成员变更历史
     */
    @Override
    public BmsProjectMemberHistory selectBmsProjectMemberHistoryByGuid(String guid)
    {
        return bmsProjectMemberHistoryMapper.selectBmsProjectMemberHistoryByGuid(guid);
    }

    /**
     * 查询项目成员变更历史列表
     * 
     * @param bmsProjectMemberHistory 项目成员变更历史
     * @return 项目成员变更历史
     */
    @Override
    public List<BmsProjectMemberHistory> selectBmsProjectMemberHistoryList(BmsProjectMemberHistory bmsProjectMemberHistory)
    {
        return bmsProjectMemberHistoryMapper.selectBmsProjectMemberHistoryList(bmsProjectMemberHistory);
    }

    /**
     * 新增项目成员变更历史
     * 
     * @param bmsProjectMemberHistory 项目成员变更历史
     * @return 结果
     */
    @Override
    public int insertBmsProjectMemberHistory(BmsProjectMemberHistory bmsProjectMemberHistory)
    {
        bmsProjectMemberHistory.setCreateTime(DateUtils.getNowDate());
        if(tokenService.getLoginUser(ServletUtils.getRequest()) != null) {
        	bmsProjectMemberHistory.setCreateBy(SecurityUtils.getLoginUser().getUser().getUserId());
        }
        
        if(null==bmsProjectMemberHistory.getGuid()||("").equals(bmsProjectMemberHistory.getGuid())){
            bmsProjectMemberHistory.setGuid(UUID.randomUUID().toString());
        }
        return bmsProjectMemberHistoryMapper.insertBmsProjectMemberHistory(bmsProjectMemberHistory);
    }

    /**
     * 修改项目成员变更历史
     * 
     * @param bmsProjectMemberHistory 项目成员变更历史
     * @return 结果
     */
    @Override
    public int updateBmsProjectMemberHistory(BmsProjectMemberHistory bmsProjectMemberHistory)
    {
        bmsProjectMemberHistory.setUpdateTime(DateUtils.getNowDate());
        bmsProjectMemberHistory.setUpdateBy(SecurityUtils.getLoginUser().getUser().getUserId());
        return bmsProjectMemberHistoryMapper.updateBmsProjectMemberHistory(bmsProjectMemberHistory);
    }

    /**
     * 批量删除项目成员变更历史
     * 
     * @param guids 需要删除的项目成员变更历史guid
     * @return 结果
     */
    @Override
    public int deleteBmsProjectMemberHistoryByGuids(String[] guids)
    {
        return bmsProjectMemberHistoryMapper.deleteBmsProjectMemberHistoryByGuids(guids);
    }

    /**
     * 删除项目成员变更历史信息
     * 
     * @param guid 项目成员变更历史guid
     * @return 结果
     */
    @Override
    public int deleteBmsProjectMemberHistoryByGuid(String guid)
    {
        return bmsProjectMemberHistoryMapper.deleteBmsProjectMemberHistoryByGuid(guid);
    }
}
